package com.hengxinguotong.zhihuichengjian.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.bumptech.glide.Glide;
import com.hengxinguotong.zhihuichengjian.R;
import com.hengxinguotong.zhihuichengjian.bean.Person;
import com.hengxinguotong.zhihuichengjian.widget.font.HXTextView;
import com.hengxinguotong.zhihuichengjian.widget.view.CircleImageView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @CopyRight 恒信国通信息科技
 * @Author WuLei
 * @Date 2018/11/1
 */

public class StudyPersonAdapter extends RecyclerAdapter<Person, StudyPersonAdapter.StudyPersonViewHolder> {

    public StudyPersonAdapter(Context context, List<Person> dataList) {
        super(context, dataList);
    }

    @Override
    public StudyPersonViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = View.inflate(context, R.layout.item_study_person, null);
        return new StudyPersonViewHolder(view);
    }

    @Override
    public void onBindViewHolder(StudyPersonViewHolder holder, int position) {
        holder.bindData(dataList.get(position));
    }

    public class StudyPersonViewHolder extends RecyclerAdapter.BaseViewHolder<Person>{
        @BindView(R.id.head_portrait_img)
        CircleImageView headPortraitImg;
        @BindView(R.id.name_tv)
        HXTextView nameTv;
        @BindView(R.id.record_tv)
        HXTextView recordTv;
        @BindView(R.id.fen_tv)
        HXTextView fenTv;
        @BindView(R.id.result_tv)
        HXTextView resultTv;
        @BindView(R.id.card_no_tv)
        HXTextView cardNoTv;
        @BindView(R.id.study_unit_tv)
        HXTextView studyUnitTv;

        public StudyPersonViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }

        public void bindData(final Person person){
            Glide.with(context)
                    .load(person.getFileName())
                    .error(R.mipmap.default_head_portrait)
                    .placeholder(R.mipmap.default_head_portrait)
                    .into(headPortraitImg);
            nameTv.setText(person.getPersonName());
            if(person.getsGrade().equals("-1")){
                recordTv.setText(R.string.no_exam);
                recordTv.setTextColor(context.getResources().getColor(R.color.color_999999));
                recordTv.setTextSize(18);
                fenTv.setVisibility(View.GONE);
            }else {
                recordTv.setText(person.getsGrade() + " ");
                recordTv.setTextColor(context.getResources().getColor(R.color.color_f288ae5));
                recordTv.setTextSize(25);
                fenTv.setVisibility(View.VISIBLE);
            }
            resultTv.setText(person.getIsPass());
            if(person.getIsPass().equals("1")){
                resultTv.setText(R.string.pass);
                resultTv.setEnabled(true);
            }else {
                resultTv.setText(R.string.no_pass);
                resultTv.setEnabled(false);
            }
            cardNoTv.setText(person.getIdentifyID());
            studyUnitTv.setText(person.getTrainDepart());

        }
    }

}
